package com.westline.unicom.test;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class testClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		    String host = "10.101.2.44";
	        int port = Integer.parseInt("10999");
	
	        try
	        {
	        	String mobile=args[0];
	        	String com=args[1];
	        	String parm="";
	        	if (args.length==3)
	        		parm=args[2];
	            System.out.println("send to:" + host + ":" + port);
	            Socket socket = new Socket(host, port);
	            System.out.println("is connected " + socket.isConnected());
	            
	            socket.setSoTimeout(10000);
	            InputStream in = (InputStream) socket.getInputStream();
	            PrintWriter out =  new  PrintWriter(socket.getOutputStream());
	            //String conn="18602533128;102011201001;201412";
	            String conn=mobile+";"+com;
	            if (!parm.equals(""))
	            	conn+=";"+parm;
	            out.println(conn);
	            out.flush();
	            InputStreamReader inSR = new InputStreamReader(in,"gb2312");  
	            BufferedReader br = new BufferedReader(inSR);  
	            //DataInputStream din = new DataInputStream(in);
	            String str = null;
	            str=br.readLine();
	            System.out.println(str);
	            str=new String(str.getBytes("utf-8"),"iso-8859-1");
	            System.out.println(str);
	            //System.out.println(com.westline.unicom.util.DateUtil.getGuserProp(str));
	           /* String rs[]=com.westline.unicom.util.DateUtil.getHistoryBill(str);

	            System.out.println(rs[0]);
	            System.out.println(rs[1]);
	            System.out.println(rs[2]);
	            System.out.println(rs[3]);
	            System.out.println(rs[4]);
	            System.out.println(rs[5]);
	            System.out.println(rs[6]);
	            System.out.println(rs[7]);
	            System.out.println(rs[8]);
	            System.out.println(rs[9]);
	            System.out.println(rs[10]);*/
	            in.close();
	            out.close();
	            socket.close();
	        }
	        catch (UnknownHostException e)
	        {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
	        catch (IOException e)
	        {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
	        catch (Exception e)
	        {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }

	}

}
